home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / MANAGEMENT.PY < prev    next >
Encoding:
Python Source  |  2000-10-09  |  7.0 KB  |  195 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64.  
  65. """Standard management interface support
  66.  
  67. $Id: Management.py,v 1.31.18.2 2000/10/09 18:16:47 brian Exp $"""
  68.  
  69. __version__='$Revision: 1.31.18.2 $'[11:-2]
  70.  
  71. import sys, Globals, ExtensionClass, urllib
  72. from Dialogs import MessageDialog
  73. from Globals import HTMLFile
  74. from string import split, join, find
  75. from AccessControl import getSecurityManager
  76.  
  77. class Tabs(ExtensionClass.Base):
  78.     """Mix-in provides management folder tab support."""
  79.  
  80.     manage_tabs__roles__=('Anonymous',)
  81.     manage_tabs     =HTMLFile('manage_tabs', globals())
  82.     
  83.  
  84.     manage_options  =()
  85.  
  86.     filtered_manage_options__roles__=None
  87.     def filtered_manage_options(self, REQUEST=None):
  88.  
  89.         validate=getSecurityManager().validate
  90.         
  91.         result=[]
  92.  
  93.         try: options=tuple(self.manage_options)
  94.         except: options=tuple(self.manage_options())
  95.  
  96.         for d in options:
  97.  
  98.             filter=d.get('filter', None)
  99.             if filter is not None and not filter(self):
  100.                 continue
  101.  
  102.             path=d.get('path', None)
  103.             if path is None: path=d['action']
  104.  
  105.             o=self.unrestrictedTraverse(path, None)
  106.             if o is None: continue
  107.  
  108.             try:
  109.                 if validate(container=self, value=o):
  110.                     result.append(d)
  111.             except:
  112.                 if not hasattr(o, '__roles__'):
  113.                     result.append(d)
  114.  
  115.         return result
  116.                     
  117.             
  118.     manage_workspace__roles__=('Anonymous',)
  119.     def manage_workspace(self, REQUEST):
  120.         """Dispatch to first interface in manage_options
  121.         """
  122.         options=self.filtered_manage_options(REQUEST)
  123.         try:
  124.             m=options[0]['action']
  125.             if m=='manage_workspace': raise TypeError
  126.         except:
  127.             raise 'Unauthorized', (
  128.                 'You are not authorized to view this object.<p>')
  129.  
  130.         if find(m,'/'):
  131.             raise 'Redirect', (
  132.                 "%s/%s" % (REQUEST['URL1'], m))
  133.         
  134.         return getattr(self, m)(self, REQUEST)
  135.     
  136.     
  137.     def tabs_path_info(self, script, path,
  138.                        # Static vars
  139.                        quote=urllib.quote,
  140.                        ):
  141.         url=script
  142.         out=[]
  143.         while path[:1]=='/': path=path[1:]
  144.         while path[-1:]=='/': path=path[:-1]
  145.         while script[:1]=='/': script=script[1:]
  146.         while script[-1:]=='/': script=script[:-1]
  147.         path=split(path,'/')[:-1]
  148.         if script: path=[script]+path
  149.         if not path: return ''
  150.         script=''
  151.         last=path[-1]
  152.         del path[-1]
  153.         for p in path:
  154.             script="%s/%s" % (script, quote(p))
  155.             out.append('<a href="%s/manage_workspace">%s</a>' % (script, p))
  156.         out.append(last)
  157.         return join(out, '/')
  158.  
  159. Globals.default__class_init__(Tabs)
  160.  
  161. class Navigation(ExtensionClass.Base):
  162.     """Basic (very) navigation UI support"""
  163.  
  164.     manage          =HTMLFile('manage', globals())
  165.     manage_menu     =HTMLFile('menu', globals())
  166.     manage_copyright=HTMLFile('copyright', globals())
  167.     manage_copyright__roles__=None
  168.  
  169.     __ac_permissions__=(
  170.         ('View management screens', ('manage', 'manage_menu',)),
  171.         )
  172.  
  173. Globals.default__class_init__(Navigation)
  174.